package edu.ubbcs.rs.backend.service.filter;

import edu.ubbcs.rs.backend.model.Reservation;
import edu.ubbcs.rs.backend.model.ReservationEvent;
import edu.ubbcs.rs.backend.model.room.Room;
import java.util.Iterator;
import java.util.List;

/**
 *
 * @author Merli András-Bertalan
 */
public class EventFilter implements Filter<ReservationEvent> {

    private ReservationEvent filterValue;

    @Override
    public void filter(List<Room> rooms) {
        System.out.println("EventFilter: " + filterValue);
        if (filterValue != null) {
            Iterator<Room> i = rooms.iterator();
            while (i.hasNext()) {
                Room room = i.next();
                boolean isEvent = false;
                for (Reservation reservation : room.getReservations()) {
                    System.out.println(reservation.getReservationEvent() + " - " + filterValue);
                    if (filterValue.equals(reservation.getReservationEvent())) {
                        isEvent = true;
                    }
                }
                if (!isEvent) {
                    i.remove();
                }
            }

        }
    }

    @Override
    public ReservationEvent getFilterValue() {
        return filterValue;
    }

    @Override
    public void setFilterValue(ReservationEvent filterValue) {
        this.filterValue = filterValue;
    }
}
